package cn.edu.scau.cmi.longyuanjun.singletonmode;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;


public class ExperimentOne extends Application{
	
	private TextField textName = new TextField();
	private String name = null;
	private String presidentName = null;
	
	@Override
	public void start(Stage primaryStage) {
		BorderPane pane = new BorderPane(); // Create a border pane
		
		pane.setTop(getHBox());
		
		// Create a scene and place it in the stage
		Scene scene = new Scene(pane);
		primaryStage.setTitle("Singleton Mode Test");
		primaryStage.setScene(scene);
		primaryStage.show();
	}
	
	private HBox getHBox() {
		HBox hBox = new HBox(15);
		Button build = new Button("new");
		hBox.setPadding(new Insets(15, 15, 15, 15));
		hBox.setStyle("-fx-background-color: gold");
		hBox.getChildren().add(new Label("name: "));
		hBox.getChildren().add(textName);
		hBox.getChildren().add(build);
		
		build.setOnAction(e -> newBulidPresident());
		
		return hBox;
		
	}
	
	private void newBulidPresident() {
		name = textName.getText();
		President president = President.getInstance(name);
		president.display();
		presidentName = president.getName();
		int num = president.getNumber();
		
		if(num == 0) {
			AnotherWindow open = new AnotherWindow();
		    open.start(new Stage());
		}else {
			ErrorWindow errWin = new ErrorWindow();
			errWin.start(new Stage());
		}
		
	}

}
